package com.retoc.oawx.service.impl;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.retoc.oawx.common.util.R;
import com.retoc.oawx.exception.OAException;
import com.retoc.oawx.service.ApproveService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.HashMap;

@Service
public class ApproveServiceImpl implements ApproveService {

    @Value("${workflow.urla}")
    private String workflow;

    @Override
    public int deleteProcess(String instanceId) {
        JSONObject json = new JSONObject();
        json.set("instanceId", instanceId);
        json.set("reason", "update");
        String url = workflow + "/approve/DeleteProcessById";
        HttpResponse resp = HttpRequest.delete(url).header("Content-Type", "application/json").body(json.toString())
                .execute();
        if (resp.getStatus() != 200) {
            throw new OAException("工作流删除失败！");
        }
        return 1;
    }
}
